<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no">
    <style>
        /** {*/
            /*padding: 0;*/
            /*margin: 0;*/
            /*list-style: none;*/
        /*}*/

        .canvas {
            border: 1px solid black;
        }
    </style>
</head>
<body>
<div class="content_body">
    <canvas class="canvas" width="700px" height="400px"></canvas>
</div>
<script>
    let canvas = document.getElementsByClassName("canvas")[0];
    let ctx = canvas.getContext('2d');
    let grideSize=20;//网格的大小
    //画多少条x轴方向的线
    let canvasHeight=ctx.canvas.height;
    let canvasWidth=ctx.canvas.width;
    let xLineTotal=Math.floor(canvasHeight/grideSize);
    for (let i = 0; i <= xLineTotal; i++) {
       ctx.beginPath();
        ctx.moveTo(0, i*grideSize-0.5);//移动画笔（x轴，y轴）
        ctx.lineTo(canvasWidth, i*grideSize-0.5);//绘制直线（轨迹，绘制路径）
        ctx.strokeStyle='ddd';
        ctx.stroke();//描边

    }
    // 画多少条x轴方向的线
    let yLineTotal=Math.floor(canvasWidth/grideSize);
    for (let i = 0; i <= yLineTotal; i++) {
        ctx.beginPath();
        ctx.moveTo(i*grideSize-0.5,0);//移动画笔（x轴，y轴）
        ctx.lineTo(i*grideSize-0.5,canvasHeight);//绘制直线（轨迹，绘制路径）
        ctx.strokeStyle='ddd';
        ctx.stroke();//描边
    }
</script>
</body>
</html>